var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isLoading: !0,
    needFix: false,
    bannerHeight: 0,
    searchCont: "",
    openmore: false,
    tabdex: "",
    popshow: false,
    list: [],
    page: 0,
    pagesize: 10,

  },
  hidepop() {
    this.setData({
      popshow: false,
      tabdex: ""
    })
  },
  shuhoukangfu:function(e){
    var zid = e.currentTarget.dataset.zid;
    var z_name = e.currentTarget.dataset.z_name;
    var agentname = e.currentTarget.dataset.agentname;
    var hid = e.currentTarget.dataset.hid;
    var keshi = e.currentTarget.dataset.keshi;
    var ks_title = e.currentTarget.dataset.ks_title;
    wx.navigateTo({
      url: '/hyb_yl/krecovery/pages/choose_operation/choose_operation?id=5&title=术后康复&keyword=shuhoukangfu&zid='+zid+'&z_name='+z_name+'&agentname='+agentname+'&hid='+hid+'&keshi='+keshi+'&ks_title='+ks_title+'&tabIndex=1',
    })
  },
  qianyue(e) {
    var that = this
    //取消签约
    wx.showModal({
      title: '签约中,签约后才可使用专家服务',
      content: '是否重新申请',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            'url': "entry/wxapp/zhuanjia.savecollectup",
            data: {
              goods_id: e.currentTarget.dataset.zid,
              cerated_type: 7,
              ifqianyue: 1,
              openid: wx.getStorageSync('openid')
            },
            success: function (res) {
              that.setData({
                page: 0,
                list: []
              })
              that.getList();
            }
          })

        }
      }
    })
  },
  doctoritems:function(e){
    var that = this;
    var zid = e.currentTarget.dataset.zid;
    var ifqianyue = e.currentTarget.dataset.ifqianyue;
    var fuwu = e.currentTarget.dataset.fuwu;
    var z_name =  e.currentTarget.dataset.z_name;
    if(ifqianyue == 1)
    {
      wx.showToast({
        title: '签约中，请等待审核',
      })
    }else if(ifqianyue == 4 || ifqianyue == 3)
    {
      wx.showToast({
        title: '请重新签约',
      })
    }else if(fuwu == false)
    {
      wx.showModal({
        title: '提示',
        content:"请先购买服务包",
        success:function(con)
        {
          if(con.confirm)
          {
            wx.navigateTo({
              url: '/hyb_yl/huanzhe/pages/private_services/private_services?zid='+zid,
            })
          }
        }
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/zhuanjiasubpages/pages/chat_list/chat_list?zid=' + zid+'&openid='+e.currentTarget.dataset.openid+'&role=0&title='+z_name
      })
    }
  },
  authorize(e){
    var that = this
    var id =e.currentTarget.dataset.id
    var change = e.currentTarget.dataset.change
    app.util.request({
      'url': "entry/wxapp/zhuanjia.upauthorize",
      data: {
        id:id,
        change:change
      },
      success: function (res) {
        that.setData({
          page: 0,
          list: []
        })
        that.getList();
      }
    })
  },
  jieyue(e) {
    var that = this
    //取消签约
    wx.showModal({
      title: '签约中,签约后才可使用专家服务',
      content: '是否取消申请',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            'url': "entry/wxapp/zhuanjia.savecollectup",
            data: {
              goods_id: e.currentTarget.dataset.zid,
              cerated_type: 7,
              ifqianyue: 3,
              openid: wx.getStorageSync('openid')
            },
            success: function (res) {
              that.setData({
                page: 0,
                list: []
              })
              that.getList();
            }
          })

        }
      }
    })

  },
  quxiao(e) {
    var that = this
    //取消签约
    wx.showModal({
      title: '签约中,签约后才可使用专家服务',
      content: '是否取消申请',
      success: function (res) {
        if (res.confirm) {
          app.util.request({
            'url': "entry/wxapp/zhuanjia.savecollectup",
            data: {
              goods_id: e.currentTarget.dataset.zid,
              cerated_type: 7,
              ifqianyue: 4,
              openid: wx.getStorageSync('openid')
            },
            success: function (res) {
              that.setData({
                page: 0,
                list: []
              })
              that.getList();
            }
          })

        }
      }
    })

  },
  tabbtn(e) {
    if (e.currentTarget.dataset.dex === this.data.tabdex) {
      this.setData({
        popshow: false,
        tabdex: "",
      })
    } else {
      wx.pageScrollTo({
        scrollTop: 100,
      })
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex,
      })
    }
  },
  itemchecked(e) {
    let arrs = this.data.tablist,
      i = this.data.tabdex,
      dex = e.currentTarget.dataset.dex
    arrs[i].list.map(item => {
      item.checked = false
    })
    arrs[i].types = arrs[i].list[dex].items
    arrs[i].list[dex].checked = true
    this.setData({
      tablist: arrs,
      popshow: false,
      tabdex: ""
    })
  },
  openmore() {
    this.setData({
      openmore: !this.data.openmore
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    var that = this;
    var typs = options.typs;
    that.setData({
      typs: typs
    })
    if (typs == 'siren_doc') {
      wx.setNavigationBarTitle({
        title: '我签约的医生',
      })
    } else if (typs == 'gz_doc') {
      wx.setNavigationBarTitle({
        title: '我关注的医生',
      })
    } else if (typs == 'gz_team') {
      wx.setNavigationBarTitle({
        title: '我关注的团队',
      })
    }
    
  },
  getList: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/zhuanjia.user_collect",
      data: {
        openid: wx.getStorageSync('openid'),
        page: that.data.page,
        pagesize: that.data.pagesize,
        typs: that.data.typs
      },
      success: function (res) {
        var page = that.data.page + 1;
        that.setData({
          list: that.data.list.concat(res.data),
          page: that.data.page,
          isLoading: !1
        })
      }
    })
  },
  onPageScroll(e) {
    let h = e.scrollTop;
    let needFix = this.data.needFix;
    let bannerHeight = this.data.bannerHeight;
    if (h > 10 + bannerHeight) {
      this.setData({
        needFix: true
      })
    } else if (h < 20) {
      this.setData({
        needFix: false
      })
    }
    this.setData({
      bannerHeight: h
    })
  },
  doctoritem(e) {
    var zid = e.currentTarget.dataset.zid;
    var ifqianyue = e.currentTarget.dataset.ifqianyue;
    if(ifqianyue == 1)
    {
      wx.showToast({
        title: '签约中，请等待审核',
      })
    }else if(ifqianyue == 4 || ifqianyue == 3)
    {
      wx.showToast({
        title: '请重新签约',
      })
      setTimeout(function(){
        wx.navigateBack({})
      })
    }else{
      wx.navigateTo({
        url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid=' + zid
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      list:[],
      page:0,
    })
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})